package com.kejiguan.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.kejiguan.ui.R;
import com.kejiguan.ui.model.DisplayArea;
import com.kejiguan.ui.model.ExhibitionNeItem;
import com.kejiguan.ui.util.CommonDate;

import java.util.List;

/**
 * Created by YYY on 16/8/30.
 */
public class DisplayNeAdapterNew extends BaseAdapter{

    private Context mContext;
    private List<ExhibitionNeItem> presenterItems;
    private LayoutInflater mInflater;
    private View.OnClickListener onClickListener;


    private int color1,color2,color3,color4,color5;

    public DisplayNeAdapterNew(Context context,List<ExhibitionNeItem> presenterItems)
    {
        this.mContext=context;
        this.presenterItems=presenterItems;
        mInflater=LayoutInflater.from(mContext);

        color1=mContext.getResources().getColor(R.color.text_color1);
        color2=mContext.getResources().getColor(R.color.text_color2);
        color3=mContext.getResources().getColor(R.color.text_color3);
        color4=mContext.getResources().getColor(R.color.text_color3);
        color5=mContext.getResources().getColor(R.color.text_color3);
    }

    public void setOnClickListener(View.OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    @Override
    public int getCount() {

        if (null==presenterItems)
        {
            return 0;
        }
        return presenterItems.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    public void setPresenterItems(List<ExhibitionNeItem> presenterItems) {
        this.presenterItems = presenterItems;
        notifyDataSetChanged();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder=null;
        if (convertView==null)
        {
            convertView=mInflater.inflate(R.layout.fragment_ne_list_item_layout,null);
            holder=new ViewHolder();
            holder.displayNameView= (TextView) convertView.findViewById(R.id.displayitem_name);
            convertView.setTag(holder);

        }else
        {
            holder= (ViewHolder) convertView.getTag();
        }

        ExhibitionNeItem presenterItem=presenterItems.get(position);
        holder.displayNameView.setText(presenterItem.getExhibitionName());
        if(CommonDate.STATE_RUNNING.equals(presenterItem.getExhibitionState()))
        {
            holder.displayNameView.setTextColor(color2);
            holder.displayNameView.setBackgroundResource(R.drawable.kjg_item_display_bg2);
        }else if (CommonDate.STATE_EXCEPTION.equals(presenterItem.getExhibitionState()))
        {
            holder.displayNameView.setTextColor(color3);
            holder.displayNameView.setBackgroundResource(R.drawable.kjg_item_display_bg3);
        }else if (CommonDate.STATE_OPEN_TIME_OUT.equals(presenterItem.getExhibitionState()))
        {
            holder.displayNameView.setTextColor(color4);
            holder.displayNameView.setBackgroundResource(R.drawable.kjg_item_display_bg3);
        }else if (CommonDate.STATE_CLOSE_TIME_OUT.equals(presenterItem.getExhibitionState()))
        {
            holder.displayNameView.setTextColor(color5);
            holder.displayNameView.setBackgroundResource(R.drawable.kjg_item_display_bg3);
        }else
        {
            holder.displayNameView.setTextColor(color1);
            holder.displayNameView.setBackgroundResource(R.drawable.kjg_item_display_bg1);
        }
        holder.displayNameView.setVisibility(View.VISIBLE);
        if (null!=onClickListener)
        {
            holder.displayNameView.setOnClickListener(onClickListener);
            holder.displayNameView.setTag(presenterItem);
        }
        return convertView;
    }

    class ViewHolder
    {
        TextView displayNameView;
    }
}
